// mock/login.js
import { defineFakeRoute } from "vite-plugin-fake-server/client";

// 模拟后端登录接口
export default defineFakeRoute([
  {
    url: "/api/login",
    method: "post",
    response: ({ body }) => {
      console.log("mock 收到登录请求", body);
      const { username, password } = body;

      if (username === "admin" && password === "123456") {
        return {
          code: 0,
          message: "登录成功",
          data: {
            token: "mock-token-abc123",
            userInfo: {
              name: "管理员",
              role: "admin",
            },
          },
        };
      }

      return {
        code: 1,
        message: "账号或密码错误",
      };
    },
  },
]);
